FROM golang:1.16-alpine AS builder

LABEL stage=go_builder

ENV CGO_ENABLED 0
ENV GOOS linux
ENV GOPROXY https://goproxy.cn,direct

WORKDIR /src/

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
    && apk add --no-cache git \
    && apk add --repository https://mirrors.ustc.edu.cn/alpine/v$(cat /etc/alpine-release | cut -c1-3)/main/ --no-cache --virtual .build-deps \
    build-base ca-certificates
ENV GOPROXY=https://goproxy.cn,direct


# RUN go env -w GOPRIVATE=gitee.com/quantum-force
ARG GOPRIVATE
ARG GIT_USER
ARG GIT_TOKEN
RUN git config --global url."https://$GIT_USER:$GIT_TOKEN@$GOPRIVATE".insteadOf "https://$GOPRIVATE"


ADD go.mod .
ADD go.sum .
RUN go mod download

COPY . .
RUN go build -o ./bin/ ./...

FROM alpine

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories && \
apk update --no-cache && apk add --no-cache ca-certificates tzdata
ENV TZ Asia/Shanghai

COPY --from=builder /src/bin/open \
                  /bin/bilin-open
ENTRYPOINT ["/bin/bilin-open"]
